from django.db import models

# Create your models here.
from utils.BaseModel import BaseModel


class CategoryModel(BaseModel):
    name = models.CharField(max_length=20, verbose_name='课程分类名称')
    parent = models.ForeignKey('self', on_delete=models.CASCADE, verbose_name='父级分类', related_name='son')
    recommend = models.BooleanField(default=False, verbose_name='是否推荐')
    ishot = models.BooleanField(default=False, verbose_name='是否热门')
    isgood = models.BooleanField(default=False, verbose_name='是否精品')

    class Meta:
        db_table = 'fgcategory'

    def __str__(self):
        return self.name


class TeacherModel(BaseModel):
    name = models.CharField(max_length=20, verbose_name='讲师名称')
    image = models.CharField(max_length=200, blank=True, null=True, verbose_name="讲师头像")
    jobtitle = models.CharField(max_length=20, verbose_name='讲师职称')
    intro = models.TextField(verbose_name='讲师简介')
    sales = models.IntegerField(default=0, verbose_name='销量')

    class Meta:
        db_table = 'fgteacher'

    def __str__(self):
        return self.name


LEVEL_CHOICES = (('1', '初级'), ('2', '中级'), ('3', '高级'))


class CourseModel(BaseModel):
    name = models.CharField(max_length=50, verbose_name='课程名称')
    image = models.CharField(max_length=200, blank=True, null=True, verbose_name='课程图片')
    price = models.DecimalField(max_digits=8, decimal_places=2, verbose_name='课程价格')
    category = models.ForeignKey(CategoryModel, on_delete=models.CASCADE, verbose_name='课程分类')
    teacher = models.ForeignKey(TeacherModel, on_delete=models.CASCADE, verbose_name='课程讲师')
    intro = models.TextField(verbose_name='课程简介')
    level = models.CharField(max_length=10, choices=LEVEL_CHOICES, verbose_name='课程难度')
    numbers = models.IntegerField(default=0, verbose_name="课程人数")
    is_home = models.BooleanField(default=True, verbose_name='是否首页推荐')
    video = models.CharField(max_length=200, default='http://127.0.0.1:8000/uploads/course/video/1.mp4', verbose_name='课程视频')
    class Meta:
        db_table = 'fgcourse'

    def __str__(self):
        return self.name
